<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">

    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- spacer 不实现任何内容 只是占位 把后面a标签撑到右侧去 -->
        <div class="spacer"></div>
        <a href="reg.html">注册</a>
        <a href="blog_lists.html">博客列表</a>
        
       
    </div>

    <!-- 页面的版心 -->
    <div class="login-container">
        <!-- 登录对话框 -->
        <div class="dialog">
            <h3>登录</h3>
            <div class="row">
                <span>用户名</span>
                <!-- 这两个框很关键 后面还要用 用id作为标识 -->
                <input type="text" id="username"> 
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password"> 
            </div>
            <div class="row">
                <button id="login-btn" onclick="mysub()">提交</button>
            </div>

        </div>

    </div>

    <script>
        function mysub(){
            //非空校验
            var username = jQuery("#username");
            var password = jQuery("#password");
            if(username.val()==""){
                alert("请先输入用户名");
                username.focus();
                return;
            }
            if(password.val()==""){
                alert("请先输入密码");
                password.focus();
                return;
            }
            //ajax请求登录接口
            jQuery.ajax({
                url: "/user/login",
                type: "post",
                data:{"username":username.val(),"password":password.val()},
                success:function(result){
                    if(result!=null&&result.code==200&&result.data!=null){
                        location.href="blog_list.html";
                    }else{
                        alert("登录失败，用户名或密码错误");
                    }
                }

            });

        }
    </script>

</body>

</html>